###EWM###
#From WinBUGS, I saved the time series of parameter values as ewmLinear#.out and ewmCAR#.out
#I saved the names of parameters as ewmLinear.ind and ewmCAR.ind
#Set-up
rm(list=ls())
library(coda)
#setwd('/Volumes/NO NAME/stateAreal/lottery/')
#setwd('C:/Temp/REPLICATION/RESULTS/')
#setwd("C:/Users/jlj94166/Documents/REPLICATION")
#setwd("C:/Users/Josh Jackson/Dropbox/Spatial Paper with Jamie/Round 2 Replication")

a<-read.coda(output.file='ewmlinearchain1.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
b<-read.coda(output.file='ewmlinearchain2.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
c<-read.coda(output.file='ewmlinearchain3.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)


### CAR convergence test
rm(list=ls())
library(coda)
#setwd('/Volumes/NO NAME/stateAreal/lottery/')
#setwd('C:/Temp/REPLICATION/RESULTS/')
#setwd("C:/Users/jlj94166/Documents/REPLICATION")

a<-read.coda(output.file='ewmlinearchain1.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
b<-read.coda(output.file='ewmlinearchain2.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
c<-read.coda(output.file='ewmlinearchain3.txt', index.file='ewmlinearindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)



###CAR convergence diagnostics 

a<-read.coda(output.file='ewmcarchain1.txt', index.file='ewmcarindex.txt', quiet=TRUE)
b<-read.coda(output.file='ewmcarchain2.txt', index.file='ewmcarindex.txt', quiet=TRUE)
c<-read.coda(output.file='ewmcarchain3.txt', index.file='ewmcarindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)




###LOTTO###
#From WinBUGS, I saved the time series of parameter values as ewmLinear#.out and ewmCAR#.out
#I saved the names of parameters as ewmLinear.ind and ewmCAR.ind
#Set-up
rm(list=ls())
library(coda)
#setwd('/Volumes/NO NAME/stateAreal/lottery/')
#setwd('C:/Temp/REPLICATION/RESULTS/')
#setwd("C:/Users/jlj94166/Dropbox/Spatial Paper with Jamie/Lotto")
#setwd("C:/Users/Josh Jackson/Dropbox/Spatial Paper with Jamie/Round 2 Replication")

a<-read.coda(output.file='lottoindchain1.txt', index.file='lottoindindex.txt', quiet=TRUE)
b<-read.coda(output.file='lottoindchain2.txt', index.file='lottoindindex.txt', quiet=TRUE)
c<-read.coda(output.file='lottoindchain3.txt', index.file='lottoindindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)



###CAR MODEL DIAGNOSTICS###
#Clean up!
rm(list=ls())
library(coda)

#Load information into coda
a<-read.coda(output.file='lottocarchain1.txt', index.file='lottocarindex.txt', quiet=TRUE)
b<-read.coda(output.file='lottocarchain2.txt', index.file='lottocarindex.txt', quiet=TRUE)
c<-read.coda(output.file='lottocarchain3.txt', index.file='lottocarindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)



###MARGALIT###
#From WinBUGS, I saved the time series of parameter values as ewmLinear#.out and ewmCAR#.out
#I saved the names of parameters as ewmLinear.ind and ewmCAR.ind
#Set-up
rm(list=ls())
library(coda)
#setwd('/Volumes/NO NAME/stateAreal/lottery/')
#setwd('C:/Temp/REPLICATION/RESULTS/')
#setwd("C:/Users/jlj94166/Dropbox/Spatial Paper with Jamie/Lotto")
#setwd("C:/Users/Josh Jackson/Dropbox/Spatial Paper with Jamie/Round 2 Replication")

a<-read.coda(output.file='margalitswchain1.txt', index.file='margalitswindex.txt', quiet=TRUE)
b<-read.coda(output.file='margalitswchain2.txt', index.file='margalitswindex.txt', quiet=TRUE)
c<-read.coda(output.file='margalitswchain3.txt', index.file='margalitswindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)



###CAR MODEL DIAGNOSTICS###
#Clean up!
rm(list=ls())
library(coda)

#Load information into coda
a<-read.coda(output.file='margalitcarchain1.txt', index.file='margalitcarindex.txt', quiet=TRUE)
b<-read.coda(output.file='margalitcarchain2.txt', index.file='margalitcarindex.txt', quiet=TRUE)
c<-read.coda(output.file='margalitcarchain3.txt', index.file='margalitcarindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)



###LINEAR MODEL DIAGNOSTICS###

#Load information into coda
#Due to the size of these files, I'm not keeping the "line" files saved.

a<-read.coda(output.file='cleanairindchain1.txt', index.file='cleanairindindex.txt', quiet=TRUE)
b<-read.coda(output.file='cleanairindchain2.txt', index.file='cleanairindindex.txt', quiet=TRUE)
c<-read.coda(output.file='cleanairindchain3.txt', index.file='cleanairindindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)

###CAR MODEL DIAGNOSTICS###
#Clean up!
rm(list=ls())
library(coda)

#Load information into coda
a<-read.coda(output.file='cleanaircarchain1.txt', index.file='cleanaircarindex.txt', quiet=TRUE)
b<-read.coda(output.file='cleanaircarchain2.txt', index.file='cleanaircarindex.txt', quiet=TRUE)
c<-read.coda(output.file='cleanaircarchain3.txt', index.file='cleanaircarindex.txt', quiet=TRUE)
d<-mcmc.list(a,b,c)

#Assess Diagnostics
#Gelman-Rubin, requires multiple chains
#Approximate convergence diagnosed when upper limit is close to 1.
gelman.diag(d)
gelman.plot(d, ask=TRUE)




